// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import axios from "axios";

/*全局引入element组件*/
Vue.use(ElementUI);
/*设置axios模块默认访问的域名代理名称*/
axios.defaults.baseURL="/shop";
/*定义请求体提的参数格式*/
axios.defaults.headers.post['Content-type'] ="application/json";

/*配置axis的请求拦截器*/
axios.interceptors.request.use(function (rs) {
     //获取token
     const token = sessionStorage.getItem("token");
     //如果token有值，才设置
     if(token){
      //设置请求头部的token值
       rs.headers.Authorization=token;
     }
     return rs;
})



/*设置全局配置的变量*/
Vue.prototype.$http = axios
/*配置axios请求体*/
Vue.config.productionTip = false
/*配置axios的响应拦截器*/
axios.interceptors.response.use(function (rs) {
  if(rs.data.code==500){
    self.$message(rs.data.msg);
  }
  if(rs.data.code==300){
    self.$message(rs.data.msg);
    //回到登录页面
    location.href="/";
  }

  return rs;
})

/* eslint-disable no-new */
var self =new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

